package com.zhang.authoritycenter.controller.authority;


import com.zhang.authoritycenter.common.model.dao.authority.AuthorityApiDO;
import com.zhang.authoritycenter.common.model.dto.authority.AddApiReqDTO;
import com.zhang.authoritycenter.common.model.dto.authority.ApiGetListReqDTO;
import com.zhang.authoritycenter.common.model.dto.authority.ApiQueryPageReqDTO;
import com.zhang.authoritycenter.common.model.dto.authority.UpdateApiReqDTO;
import com.zhang.authoritycenter.common.model.dto.common.IdListReqDTO;
import com.zhang.authoritycenter.service.IAuthorityApiService;
import com.zhang.infrastructure.model.KingHoodResponseVO;
import com.zhang.mysql.model.PageResponseVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 组织
 *
 * @author zhangFanJun
 * @date 2023-12-06 10:42
 **/
@RequestMapping("/api")
@Slf4j
@RequiredArgsConstructor
@RestController
public class ApiController {

    private final IAuthorityApiService apiService;

    /**
     * api分页列表
     *
     * @param in api信息
     * @return api信息
     * @author zfj
     * @date 2023/12/18
     */
    @PostMapping("/queryPage")
    public KingHoodResponseVO<PageResponseVO<AuthorityApiDO>> queryPage(@RequestBody ApiQueryPageReqDTO in) {
        return KingHoodResponseVO.success(apiService.queryPage(in));
    }

    /**
     * 新建api
     *
     * @param in api信息
     * @return api信息
     * @author zfj
     * @date 2023/12/18
     */
    @PostMapping("/addApi")
    public KingHoodResponseVO<AuthorityApiDO> addApi(@RequestBody AddApiReqDTO in) {
        return KingHoodResponseVO.success(apiService.addApi(in));
    }

    /**
     * 获取api信息
     *
     * @param id apiId
     * @return api信息
     * @author zfj
     * @date 2023/12/18
     */
    @GetMapping("/getApi/{id}")
    public KingHoodResponseVO<AuthorityApiDO> getApi(@PathVariable("id") Long id) {
        return KingHoodResponseVO.success(apiService.getApi(id));
    }

    /**
     * api信息修改
     *
     * @param in api信息
     * @return api信息
     * @author zfj
     * @date 2023/12/18
     */
    @PostMapping("/updateApi")
    public KingHoodResponseVO<AuthorityApiDO> updateApi(@Valid @RequestBody UpdateApiReqDTO in) {
        return KingHoodResponseVO.success(apiService.updateApi(in));
    }

    /**
     * 批量删除api
     *
     * @param in api的id信息
     * @return 是否删除成功
     * @author zfj
     * @date 2023/12/18
     */
    @PostMapping("/deleteApiBatch")
    public KingHoodResponseVO<Boolean> deleteApiBatch(@Valid @RequestBody IdListReqDTO in) {
        return KingHoodResponseVO.success(apiService.deleteApiBatch(in.getIdList()));
    }

    /**
     * <p>下拉列</p>
     * 获取api
     *
     * @param in 入参
     * @return api列表
     * @author zfj
     * @date 2023/12/19
     */
    @PostMapping("/apiList")
    public KingHoodResponseVO<List<AuthorityApiDO>> apiList(@RequestBody ApiGetListReqDTO in) {

        return KingHoodResponseVO.success(apiService.getList(in));
    }

}
